package cn.shuangbofu.guice.test;

import java.security.SecureRandom;
import java.util.Objects;

/**
 * Created by shuangbofu on 2020-04-17 14:59
 */
public class Entity {

    public static final String NAME = "鸣人";
    private static SecureRandom random = new SecureRandom();
    private String name;
    private int priority;

    public Entity(String num) {
        name = NAME + num + "号";
        priority = random.nextInt(4) + 1;
        print();
    }

    private void print() {
        System.out.println("分身出" + name + "-" + (priority == 4 ? "高级" : "低级"));
    }

    public int rubBalls() {
        int size = getSize();
        System.out.println(name + "搓丸子" + size + "颗");
        return size;
    }

    private int getSize() {
        return random.nextInt(priority * 10) + 10;
    }


    public int getPriority() {
        return priority;
    }

    public String getName() {
        return name;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Entity entity = (Entity) o;
        return
                Objects.equals(name, entity.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
